home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60src.lha / Vim / vim60 / src / macros.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-29  |  5.8 KB  |  196 lines

  1. /* vi:set ts=8 sts=4 sw=4:
  2.  *
  3.  * VIM - Vi IMproved    by Bram Moolenaar
  4.  *
  5.  * Do ":help uganda"  in Vim to read copying and usage conditions.
  6.  * Do ":help credits" in Vim to see a list of people who contributed.
  7.  */
  8.  
  9. /*
  10.  * macros.h: macro definitions for often used code
  11.  */
  12.  
  13. /*
  14.  * pchar(lp, c) - put character 'c' at position 'lp'
  15.  */
  16. #define pchar(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
  17.  
  18. /*
  19.  * Position comparisons
  20.  */
  21. #ifdef FEAT_VIRTUALEDIT
  22. # define lt(a, b) (((a).lnum != (b).lnum) \
  23.            ? (a).lnum < (b).lnum \
  24.            : (a).col != (b).col \
  25.                ? (a).col < (b).col \
  26.                : (a).coladd < (b).coladd)
  27. # define ltp(a, b) (((a)->lnum != (b)->lnum) \
  28.            ? (a)->lnum < (b)->lnum \
  29.            : (a)->col != (b)->col \
  30.                ? (a)->col < (b)->col \
  31.                : (a)->coladd < (b)->coladd)
  32. # define equal(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col) && ((a).coladd == (b).coladd))
  33. #else
  34. # define lt(a, b) (((a).lnum != (b).lnum) \
  35.            ? ((a).lnum < (b).lnum) : ((a).col < (b).col))
  36. # define ltp(a, b) (((a)->lnum != (b)->lnum) \
  37.            ? ((a)->lnum < (b)->lnum) : ((a)->col < (b)->col))
  38. # define equal(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col))
  39. #endif
  40.  
  41. #define ltoreq(a, b) (lt(a, b) || equal(a, b))
  42.  
  43. /*
  44.  * lineempty() - return TRUE if the line is empty
  45.  */
  46. #define lineempty(p) (*ml_get(p) == NUL)
  47.  
  48. /*
  49.  * bufempty() - return TRUE if the current buffer is empty
  50.  */
  51. #define bufempty() (curbuf->b_ml.ml_line_count == 1 && *ml_get((linenr_T)1) == NUL)
  52.  
  53. /*
  54.  * On some systems toupper()/tolower() only work on lower/uppercase characters
  55.  * Careful: Only call TO_UPPER() and TO_LOWER() with a character in the range
  56.  * 0 - 255.  toupper()/tolower() on some systems can't handle others.
  57.  * Note: for UTF-8 use utf_toupper() and utf_tolower().
  58.  */
  59. #ifdef MSWIN
  60. #  define TO_UPPER(c)    toupper_tab[(c) & 255]
  61. #  define TO_LOWER(c)    tolower_tab[(c) & 255]
  62. #else
  63. # ifdef BROKEN_TOUPPER
  64. #  define TO_UPPER(c)    (islower(c) ? toupper(c) : (c))
  65. #  define TO_LOWER(c)    (isupper(c) ? tolower(c) : (c))
  66. # else
  67. #  define TO_UPPER    toupper
  68. #  define TO_LOWER    tolower
  69. # endif
  70. #endif
  71.  
  72. /*
  73.  * MB_ISLOWER() and MB_ISUPPER() are to be used on multi-byte characters.  But
  74.  * don't use them for negative values or values above 0x100 for DBCS.
  75.  */
  76. #ifdef FEAT_MBYTE
  77. # define MB_ISLOWER(c)    (enc_utf8 && (c) > 0x80 ? utf_islower(c) : islower(c))
  78. # define MB_ISUPPER(c)    (enc_utf8 && (c) > 0x80 ? utf_isupper(c) : isupper(c))
  79. # define MB_TOLOWER(c)    (enc_utf8 && (c) > 0x80 ? utf_tolower(c) : TO_LOWER(c))
  80. # define MB_TOUPPER(c)    (enc_utf8 && (c) > 0x80 ? utf_toupper(c) : TO_UPPER(c))
  81. #else
  82. # define MB_ISLOWER(c)    islower(c)
  83. # define MB_ISUPPER(c)    isupper(c)
  84. # define MB_TOLOWER(c)    TO_LOWER(c)
  85. # define MB_TOUPPER(c)    TO_UPPER(c)
  86. #endif
  87.  
  88. /* Like isalpha() but reject non-ASCII characters.  Can't be used with a
  89.  * special key (negative value). */
  90. #ifdef EBCDIC
  91. # define ASCII_ISALPHA(c) isalpha(c)
  92. # define ASCII_ISALNUM(c) isalnum(c)
  93. # define ASCII_ISLOWER(c) islower(c)
  94. # define ASCII_ISUPPER(c) isupper(c)
  95. #else
  96. # define ASCII_ISALPHA(c) ((c) < 0x7f && isalpha(c))
  97. # define ASCII_ISALNUM(c) ((c) < 0x7f && isalnum(c))
  98. # define ASCII_ISLOWER(c) ((c) < 0x7f && islower(c))
  99. # define ASCII_ISUPPER(c) ((c) < 0x7f && isupper(c))
  100. #endif
  101.  
  102. /* macro version of chartab().
  103.  * Only works with values 0-255!
  104.  * Doesn't work for UTF-8 mode with chars >= 0x80. */
  105. #define CHARSIZE(c)    (chartab[c] & CT_CELL_MASK)
  106.  
  107. #ifdef FEAT_LANGMAP
  108. /*
  109.  * Adjust chars in a language according to 'langmap' option.
  110.  * NOTE that there is NO overhead if 'langmap' is not set; but even
  111.  * when set we only have to do 2 ifs and an array lookup.
  112.  * Don't apply 'langmap' if the character comes from the Stuff buffer.
  113.  * The do-while is just to ignore a ';' after the macro.
  114.  */
  115. # define LANGMAP_ADJUST(c, condition) do { \
  116.     if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \
  117.         c = langmap_mapchar[c]; \
  118.     } while (0)
  119. #endif
  120.  
  121. /*
  122.  * vim_isbreak() is used very often if 'linebreak' is set, use a macro to make
  123.  * it work fast.
  124.  */
  125. #define vim_isbreak(c) (breakat_flags[(char_u)(c)])
  126.  
  127. /*
  128.  * On VMS file names are different and require a translation.
  129.  * On the Mac open() has only two arguments.
  130.  */
  131. #ifdef VMS
  132. # define mch_access(n, p)    access(vms_fixfilename(n), (p))
  133.                 /* see mch_open() comment */
  134. # define mch_fopen(n, p)    fopen(vms_fixfilename(n), (p))
  135. # define mch_fstat(n, p)    fstat(vms_fixfilename(n), (p))
  136.     /* VMS does not have lstat() */
  137. # define mch_stat(n, p)        stat(vms_fixfilename(n), (p))
  138. #else
  139. # define mch_access(n, p)    access((n), (p))
  140. # define mch_fopen(n, p)    fopen((n), (p))
  141. # define mch_fstat(n, p)    fstat((n), (p))
  142. # define mch_lstat(n, p)    lstat((n), (p))
  143. # ifdef MSWIN    /* has it's own mch_stat() function */
  144. #  define mch_stat(n, p)    vim_stat((n), (p))
  145. # else
  146. #  define mch_stat(n, p)    stat((n), (p))
  147. # endif
  148. #endif
  149.  
  150. #ifdef MACOS_CLASSIC
  151. /* MacOS classic doesn't support perm but MacOS X does. */
  152. # define mch_open(n, m, p)    open((n), (m))
  153. #else
  154. # ifdef VMS
  155. /*
  156.  * It is possible to force some record format with:
  157.  * #  define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p)), "rat=cr", "rfm=stmlf", "mrs=0")
  158.  * but it is not recomended, because it can destroy indexes etc.
  159.  */
  160. #  define mch_open(n, m, p)    open(vms_fixfilename(n), (m), (p))
  161. # else
  162. #  define mch_open(n, m, p)    open((n), (m), (p))
  163. # endif
  164. #endif
  165.  
  166. /*
  167.  * Encryption macros.  Mohsin Ahmed, mosh@sasi.com 98-09-24
  168.  * Based on zip/crypt sources.
  169.  */
  170.  
  171. #ifdef FEAT_CRYPT
  172.  
  173. #ifndef __MINGW32__
  174. # define PWLEN 80
  175. #endif
  176.  
  177. /* encode byte c, using temp t.  Warning: c must not have side effects. */
  178. # define ZENCODE(c, t)  (t = decrypt_byte(), update_keys(c), t^(c))
  179.  
  180. /* decode byte c in place */
  181. # define ZDECODE(c)   update_keys(c ^= decrypt_byte())
  182.  
  183. #endif
  184.  
  185. #ifdef STARTUPTIME
  186. # define TIME_MSG(s) time_msg(s, NULL)
  187. #else
  188. # define TIME_MSG(s)
  189. #endif
  190.  
  191. #ifdef FEAT_VREPLACE
  192. # define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG))
  193. #else
  194. # define REPLACE_NORMAL(s) ((s) & REPLACE_FLAG)
  195. #endif
  196.